home *** CD-ROM | disk | FTP | other *** search
- {****************************************************************************
- * *
- * SpotSavr.pas: Plug-in animation module for SSaveDem.pas *
- * *
- * Rev. 0.1 19.4.93 MK IR *
- * *
- ****************************************************************************}
-
- { Name for this Screen Saver - shows up in Control Panel: }
- {$D SCRNSAVE Spotlight }
-
- const AppName: PChar = 'Screen Saver.Spotlight' ;
-
- type
- PMySaverWin = ^TMySaverWin;
- TMySaverWin = Object(TScSaverWin)
- zx, zy, cx, cy, vx, vy, d: integer;
- Desktop: hBitmap;
- procedure SetupWindow; virtual;
- procedure DoTheShow; virtual;
- destructor Done; virtual;
- end;
-
- {****************************************************************************
- * *
- * T M y S a v e r W i n . S e t u p W i n d o w *
- * *
- * OUTPUT: zx, zy = screen dimensions *
- * vx, vy = speed of spotlight *
- * cx, cy = starting position *
- * d = spotlight diameter (all of the above in pixels) *
- * Desktop= bitmap with copy of actual desktop picture *
- * *
- ****************************************************************************}
-
- procedure TMySaverWin.SetupWindow;
-
- var WinDC, MemDC: hDC;
-
- begin
- inherited SetupWindow;
- zx := GetSystemMetrics (SM_CXSCREEN) ; { get screen dimensions }
- zy := GetSystemMetrics (SM_CYSCREEN) ;
- randomize;
- cx := random (zx div 2) + 1; { get starting position }
- cy := random (zy div 2) + 1;
- vx := -1 + 2*random (2); { get speed: }
- vy := -1 + 2*random (2); { vx, vy = 1 or -1 }
- d := zy div 4; { diameter }
-
- WinDC := TestHandle (GetDC (hWindow)); { copy actual video RAM.. }
- MemDC := TestHandle (CreateCompatibleDC (WinDC));
- Desktop := TestHandle (CreateCompatibleBitmap (WinDC, zx, zy));
- TestHandle (SelectObject (MemDC, Desktop));
- TestBool (BitBlt (MemDC, 0, 0, zx, zy, WinDC, 0, 0, SRCCOPY));
- DeleteDC (MemDC);
- ReleaseDC (hWindow, WinDC); {..into bitmap "desktop" }
-
- end; { SetupWindow }
-
-
- {****************************************************************************
- * *
- * T M y S a v e r W i n . D o T h e S h o w *
- * *
- * INPUT: zx, zy = screen dimensions *
- * vx, vy = speed of spotlight *
- * cx, cy = actual spotlight position *
- * d = spotlight diameter (all of the above in pixels) *
- * Desktop= bitmap with copy of actual desktop picture *
- * *
- * OUTPUT: vx, vy = new speed of spotlight *
- * cx, cy = new actual position *
- * *
- ****************************************************************************}
-
- procedure TMySaverWin.DoTheShow ;
-
- var WinDC, MemDC: hDC;
- CircleRgn, BackGndRgn: hRgn;
-
- begin
- WinDC := TestHandle (GetDC (hWindow));
- MemDC := TestHandle (CreateCompatibleDC (WinDC));
- TestHandle (SelectObject (MemDC, Desktop)); { get a DC with desktop bitmap }
-
- if ((cx <= 0) or (cx+d >= zx)) then vx := -vx; { bounce light at edges }
- if ((cy <= 0) or (cy+d >= zy)) then vy := -vy;
- cx := cx+vx; { calculate new position }
- cy := cy+vy;
-
- { Build the "spotlight region" that is to receive (part of) the bitmap: }
- CircleRgn := TestHandle (CreateEllipticRgn (cx, cy, cx+d, cy+d));
- { Build a rectangle region that's a bit bigger than the spotlight circle: }
- BackGndRgn := TestHandle (CreateRectRgn (cx-2, cy-2, cx+d+2, cy+d+2));
- { Subtract the circle region from the rectangle region: }
- TestHandle (CombineRgn (BackGndRgn, BackGndRgn, CircleRgn, RGN_DIFF));
- { Paint BackGndRgn black: this will erase the area surrounding the spotlight: }
- TestBool (FillRgn (WinDC, BackGndRgn, GetStockObject (black_brush)));
-
- TestHandle (SelectObject (WinDC, CircleRgn)); { clipping region }
- TestBool (BitBlt (WinDC, 0, 0, zx, zy, MemDC, 0, 0, SRCCOPY));
- { copy bitmap -> screen }
-
- DeleteDC (MemDC);
- ReleaseDC (hWindow, WinDC);
- DeleteObject (CircleRgn);
- DeleteObject (BackGndRgn);
- end; { DoTheShow }
-
- {****************************************************************************
- * *
- * T M y S a v e r W i n . D o n e *
- * *
- ****************************************************************************}
-
- destructor TMySaverWin.Done; { cleans up }
- begin
- DeleteObject (Desktop);
- inherited done;
- end;
-
-
-